#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>


static int my_pdrv_probe(struct platform_device *pdev)
{
	int irqnum;
	struct resource *res;

	pr_info("Hello! device probed\n");

	/* get IRQ number */
	irqnum = platform_get_irq(pdev, 0);
	pr_info("IRQ number of Device: %d\n", irqnum);
	
	/* get memory resource */
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res) {
		pr_err("First resource not available\n");
		return -1;
	}
	pr_info("memory resource start:0x%x\n", res->start);
	pr_info("memory resource end:0x%x\n", res->end);
	
	return 0;
}

static int my_pdrv_remove(struct platform_device *pdev)
{
	pr_info("Good bye reader\n");
	return 0;
}

static struct platform_driver mypdrv = {
	.probe = my_pdrv_probe,
	.remove = my_pdrv_remove,
	.driver = {
		.name = "platform_demo",
		.owner = THIS_MODULE,
	},
};

static int __init my_pdrv_init(void)
{
	pr_info("Hello guy\n");

	/* Registering with kernel */
	platform_driver_register(&mypdrv);
	return 0;
}

static void __exit my_pdrv_exit(void)
{
	pr_info("Good bye Guy\n");

	platform_driver_unregister(&mypdrv);
}


module_init(my_pdrv_init);
module_exit(my_pdrv_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Meng");
MODULE_DESCRIPTION("My platform demo module");